# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy

from components.custom_item import UpdateCustomItem
from utils.tools import del_redundant_blank_character


class NetCreditGradeAItem(UpdateCustomItem):
    __table_name__ = 'net_credit_grade_a'
    __update_key__ = ["taxpayer_id", "year", "company_name"]
    company_name = scrapy.Field()
    taxpayer_id = scrapy.Field()
    year = scrapy.Field()
    province = scrapy.Field()

    def pre_to_db(self):
        """
        入库前的处理
        """
        self.company_name = self.process_str(self.company_name).replace('\\', '')
        self.taxpayer_id = self.process_str(self.taxpayer_id)

    @staticmethod
    def process_str(value):
        """
        处理字符串
        :param value:
        :return:
        """
        if value is None:
            return ""
        return del_redundant_blank_character(value)
